package com.example.zhugenew.model;

import com.example.myhttplibrary.client.HttpClient;
import com.example.mymvplibrary.callback.BaseModelCallback;
import com.example.mymvplibrary.model.BaseModel;
import com.example.zhugenew.bean.BansBean;
import com.example.zhugenew.callback.HttpCallBack;
import com.example.zhugenew.concation.MainConations;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.trello.rxlifecycle2.LifecycleProvider;

import java.util.HashMap;
import java.util.List;

public class HomeModel<T> implements BaseModel, MainConations.MainModel {

    @Override
    public void getData(BaseModelCallback mainCallBack, LifecycleProvider lifecycleProvider, String url, int type, HashMap map) {
        new HttpClient.Builder()
                .setBaseUrl("https://api.zhuge.com/")
                .setApiUrl(url)
                .setParamser(map)
                .setLifecycleProvider(lifecycleProvider)
                .post()
                .build()
                .excute(new HttpCallBack<T>() {
                    @Override
                    protected void error(String error, int code) {
                        mainCallBack.onError(error, code);
                    }

                    @Override
                    protected void onSucess(T t) {
                        mainCallBack.onSucess(t, type);
                    }

                    @Override
                    public T convert(JsonElement jsonElement) {
                        return (T) jsonElement;
                    }
                });
    }
}
 